package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    //@Select("select e.*,d.name as deptName from emp e left join dept d on e.dept_id=d.id order by e.update_time desc ")
    public List<Emp> list(EmpQueryParam empQueryParam);

    //新增员工基本信息
    @Options(useGeneratedKeys = true,keyProperty = "id")//主键返回 获取到生成的主键
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time)" +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);
/*
* 批量删除员工信息
* */
    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);
    /*
    * 统计员工职位人数
    * */
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();
    @MapKey("name")
    List<Map<String, Object>> countEmpGenderData();

    List<Emp> findAll();

    /*查询是否有某一部门的*/
    List<Emp> findDeptId(Integer id);
/*
* 根据用户名和密码查询员工信息
* */
    @Select("select id,username,name from emp where username=#{username} and password=#{password}")
    Emp selectByUsernameAndPassword(Emp emp);


    /*-----------------------原始分页查询--------------------*/
  /*  @Select("select count(*) from emp e left join dept d on e.dept_id=d.id")
    public long count();
    @Select("select e.*,d.name as deptName from emp e left join dept d on e.dept_id=d.id order by e.update_time limit #{start},#{pageSize}")
    public List<Emp> list(Integer start,Integer pageSize);*/
}
